	
var vue = new Vue({
  el: '#pageDiv',
  data :{
	  tableData : [],
	  transferLData : [],
	  transferRData : [],
	  loading: false,
	  currentPage : 1,
	  pagesize : 10,
	  totalSize : 10,
	  //url
	  toListUrl:'/userJob/toList',
	  queryUrl:COMMON_URL.URL+'userJob/list',
	  editUrl:COMMON_URL.URL+'userJob/edit',
	  saveUrl:COMMON_URL.URL+'userJob/add',
	  deleteUrl: COMMON_URL.URL+'userJob/delete',
	  visible2: false,
	  dialogEdit:false,
	  dialogAdd:false,
	  dialogConfig:false,
	  dialogTitle:'',
	  roleId:"",
	  job:{
		  id:'',
		  jobCode : '',
		  jobDesc : '',
		  jobContent : ''
	  },
	  jobAdd:{
		  jobCode : '',
		  jobDesc : '',
		  jobContent : ''
	  },
	  //form校验规则
	  rules:{
		  jobCode:[
            { required: true, message: '请输入作业编码', trigger: 'blur' }
          ],
          jobDesc:[
	        { required: true, message: '请输入作业描述', trigger: 'blur' }
	      ],
	      jobContent:[
	        { required: true, message: '请输入作业内容', trigger: 'blur' }
	      ]
	  }
  },
  methods:{
	  //查询数据
	  loadData(pageNum,pageSize){
		  var tables = this.tableData ;
		  $.ajax({
				url : this.queryUrl,
				dataType : 'json',
				type : 'get',
				data : {pageNum:pageNum,pageSize:pageSize},
				success : function(data){
					if(data.ok){
						var value = data.data.list;
						vue.tableData = value;
						vue.currentPage = data.data.currentPage;
						vue.totalSize = data.data.allCounts;
					}
				}
		  });
	  },
	  //分页
	  handleSizeChange(val){
		this.pagesize = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
	  //分页
	  handleCurrentChange(val){
		this.currentPage = val;
		this.loadData(this.currentPage,this.pagesize);
	  },
	  //跳转到新页面
	  openTabById(url,val){
		  $.get(url+val,function(data){
				$('#mainApp').html(data);
		  });
	  },
      //打开成功提示
      successMsg() {
	      this.$message({
	        showClose: true,
	        message: '操作成功',
	        type: 'success'
	      });
	  },
	  //打开失败提示
      errorMsg() {
	      this.$message({
	        showClose: true,
	        message: '操作失败',
	        type: 'error'
	      });
	  },
	  openAddDialog(){
		  this.jobAdd.jobCode = '';
    	  this.jobAdd.jobDesc ='';
    	  this.jobAdd.jobContent ='';
		  this.dialogAdd = true;  
	  },
	  //关闭弹窗
      closeDialog(){
    	  this.dialogEdit = false;
    	  this.dialogAdd = false;
    	  this.jobAdd.jobCode = '';
    	  this.jobAdd.jobDesc ='';
    	  this.jobAdd.jobContent ='';
    	  vue.loadData(vue.currentPage, vue.pagesize);
      },
      //保存作业配置
      addForm(formName){
    	  this.$refs[formName].validate((valid) => {
              if (valid) {
                $.ajax({
    				url : this.saveUrl,
    				dataType : 'json',
    				type : 'post',
    				contentType: "application/json",
    	    		data : JSON.stringify(this.jobAdd),
    				success : function(data){
    					if(data.ok){
    						vue.dialogAdd = false;
    						vue.successMsg();
    			      	  	//刷新页面数据
    						vue.loadData(vue.currentPage, vue.pagesize);
    					}else{
    						vue.errorMsg();
    						vue.loadData(vue.currentPage, vue.pagesize);
    					}
    				}
                });
              } else {
                return false;
              }
          });
      },
	  //获取当前行的值
      getRoleData(row){
		  //打开修改弹窗
    	  this.dialogEdit =true;
    	  vue.job = row;
      },
      //保存修改
      editForm(){
    	  $.ajax({
				url : this.editUrl,
				type : 'post',
				dataType : 'json',
				contentType: "application/json",
				data :JSON.stringify(this.job),
				async: false,
				success : function(data){
					if(data.ok){
						vue.successMsg();
						vue.dialogEdit =false;
				    	//刷新页面数据
						//vue.loadData(vue.currentPage, vue.pagesize);
					}else{
						vue.errorMsg();
						vue.loadData(vue.currentPage, vue.pagesize);
					}
				}
		  });
      },
      //删除
      deleteConfig(index,row,value){
		  const h = this.$createElement;
		  this.$msgbox({
			  title : "警告",
			  message : h('p', null, [
	            h('span', null, '你将要删除 '),
	            h('i', { style: 'color: teal' }, row.roleName),
	            h('span', null, ' 此操作将会一并删除 '),
	            h('i', { style: 'color: teal' }, "详细权限配置"),
	            h('span', null, ' ！请考虑好再操作！'),
	          ]),
	          showCancelButton: true,
	          confirmButtonText: '确定',
	          cancelButtonText: '取消',
	          beforeClose: (action, instance, done) => {
	              if (action === 'confirm') {
	                instance.confirmButtonLoading = true;
	                instance.confirmButtonText = '执行中...';
	        		$.ajax({
	        			type : 'get',
	        			dataType : 'json',
	        			data : {id : row.id},
	        			url : this.deleteUrl,
	        			success : function(data){
	        				if(data.ok){
	        					done();
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	        					//刷新页面数据
	        					vue.loadData(vue.currentPage, vue.pagesize);
	        				}else{
	        					setTimeout(() => {
	                				instance.confirmButtonLoading = false;
	                			}, 300);
	    					}
	        			}
	        		});
	              }else{
	                done();
	              }
	          }
		  }).then(action => {
	          this.$message({
	        	  showClose: true,
	              type: 'success',
	              message: '操作成功'
	          });
	      });
	  }
   }
});
	

//载入数据
vue.loadData(vue.currentPage, vue.pagesize);

